/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skybash;

import java.util.ArrayList;
import java.util.HashMap;
import lev.Ln;
import skyproc.*;
import skyproc.gui.SPProgressBarPlug;

/**
 *
 * @author pc tech
 */
public class WeapMergerPatch {

    //Lists forms w/ Weap's.
    HashMap<FormID, WEAP> weapList = new HashMap<>();
    //Lists all the base Weap's from the Skyrim.esm, so base data isn't considered changed at any point.
    final HashMap<FormID, WEAP> baseWeapList = new HashMap<>();
    ArrayList<WEAP> deepCopiedList = new ArrayList<>();
    //Grab reference to the mods map.
    HashMap<Mod, ModTags> mods;
    //Storage for modTags.
    ModTags modTags;
    //Full logging boolean for neatness in below code.
    boolean fullLogging;
    //Data locking map.
    HashMap<String, Boolean> dataLock;
    //Storage mod used in counter.
    Mod temp;

    //Constructor for pulling mod tags.
    public WeapMergerPatch(HashMap mods) {
        this.mods = mods;
    }

    public void mergeNPCs() {
        WEAP newWeap; //Storage Weap used to reference new with old.

        //Set full logging.
        fullLogging = SkyBash.save.getBool(SkyBashSaveFile.GUISettings.FULL_LOGGING);

        SPProgressBarPlug.progress.setStatus("Processing Base Weapons");
        SPProgressBarPlug.progress.incrementBar();

        for (WEAP w : SPGlobal.getDB().getMod(0).getWeapons()) {
            //Store the list of base Weap's.
            baseWeapList.put(w.getForm(), w);
        }

        //Iterate through mod lists.
        for (int i = 1; i < SPGlobal.getDB().numMods(); i++) {
            temp = SPGlobal.getDB().getMod(i);
            SPProgressBarPlug.progress.setStatus("Processing Weapons from " + temp.getName());
            SPProgressBarPlug.progress.incrementBar();

            //For other mods, cross and merge data and add to the global patch.
            for (WEAP w : temp.getWeapons()) {
                if (!weapList.containsKey(w.getForm())) {
                    weapList.put(w.getForm(), w);
                } else {
                    newWeap = weapList.get(w.getForm());

                    //Get the mod tags for the merger.
                    if (mods != null && !mods.isEmpty() && mods.containsKey(temp)) {
                        modTags = mods.get(temp);
                    } else {
                        modTags = new ModTags(true);
                    }

                    //Start the NPC merger.
                    SPGlobal.log("Weapon MERGER: ", "Merging Weapon " + newWeap.getEDID() + " from " + temp.getName());
                    newWeap = mergeWeapons(newWeap, w);

                    //Add the edited Weap to the map, replacing the old.
                    weapList.put(w.getForm(), newWeap);

                    //Add the Weap to the patch.  If it's edited later, it'll override.
                    SPGlobal.getGlobalPatch().addRecord(newWeap);
                }
            }
        }
    }

    private WEAP mergeWeapons(WEAP w, WEAP newWeap) {

        //Holder for array lists of items, perks, spells, etc.
        ArrayList tempList;
        ArrayList tempListW;
        ArrayList tempListBase;

        //Grabs the base Weap from the list, and copies it below to retain the reference data.
        WEAP tempWEAP;
        if (baseWeapList.containsKey(w.getForm())) {
            tempWEAP = baseWeapList.get(w.getForm());
        } else {
            tempWEAP = w;
        }

        //Initializes it to the temp Weap.
        WEAP baseWeap = tempWEAP;

        //Deep copies the NPC so the base Weap is retained.
        if (!deepCopiedList.contains(tempWEAP)) {
            baseWeap = (WEAP) Ln.deepCopy(tempWEAP);
            baseWeapList.put(baseWeap.getForm(), baseWeap);
            deepCopiedList.add(baseWeap);
        }

        /*
         * Script merging.
         */
        if (modTags.scripts) {
            tempList = newWeap.scripts.getScripts();
            tempListW = w.scripts.getScripts();
            tempListBase = baseWeap.scripts.getScripts();
            for (int i = 0; i < tempListBase.size(); i++) {
                if (!tempList.contains((ScriptRef) tempListBase.get(i))) {
                    w.scripts.removeScript((ScriptRef) tempListBase.get(i));
                    if (fullLogging) {
                        SPGlobal.log("Scripts: ", "Removed script " + ((ScriptRef) tempListBase.get(i)).getName() + " to "
                                + newWeap.getEDID() + " from Mod " + temp.getName());
                    }
                }
            }
            for (int i = 0; i < tempList.size(); i++) {
                if (!tempListW.contains((ScriptRef) tempList.get(i)) && !tempListBase.contains((ScriptRef) tempList.get(i))) {
                    w.scripts.addScript((ScriptRef) tempList.get(i));
                    if (fullLogging) {
                        SPGlobal.log("Scripts: ", "Merged script " + ((ScriptRef) tempList.get(i)).getName() + " to "
                                + newWeap.getEDID() + " from Mod " + temp.getName());
                    }
                }
            }
        }

        /*
         * Keyword merging.
         */
        if (modTags.keywords) {
            tempList = newWeap.keywords.getKeywordRefs();
            tempListW = w.keywords.getKeywordRefs();
            tempListBase = baseWeap.keywords.getKeywordRefs();
            for (int i = 0; i < tempListBase.size(); i++) {
                if (!tempList.contains((FormID) tempListBase.get(i))) {
                    w.keywords.removeKeywordRef((FormID) tempListBase.get(i));
                    if (fullLogging) {
                        SPGlobal.log("Scripts: ", "Removed Keyword " + ((FormID) tempListBase.get(i)) + " to "
                                + newWeap.getEDID() + " from Mod " + temp.getName());
                    }
                }
            }
            for (int i = 0; i < tempList.size(); i++) {
                if (!tempListW.contains((FormID) tempList.get(i)) && !tempListBase.contains((FormID) tempList.get(i))) {
                    w.keywords.addKeywordRef((FormID) tempList.get(i));
                    if (fullLogging) {
                        SPGlobal.log("Keywords: ", "Merged Keyword " + tempList.get(i) + " to "
                                + newWeap.getEDID() + " from Mod " + temp.getName());
                    }
                }
            }
        }

        /*
         * Weapon Flags.
         */
        for (WEAP.WeaponFlag flag : WEAP.WeaponFlag.values()) {
            if (w.get(flag) != newWeap.get(flag) && newWeap.get(flag) != baseWeap.get(flag)) {
                w.set(flag, newWeap.get(flag));
                if (fullLogging) {
                    SPGlobal.log("Weapon Flags: ", "Merged " + flag.toString() + " to "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Bound Weapon Sounds.
         */
        if (modTags.Sounds) {
            if (w.getBoundWeaponSound() != newWeap.getBoundWeaponSound() && newWeap.getBoundWeaponSound() != baseWeap.getBoundWeaponSound()) {
                w.setBoundWeaponSound(newWeap.getBoundWeaponSound());
                if (fullLogging) {
                    SPGlobal.log("Sounds: ", "Merged Bound Weapon Sound to " + w.getBoundWeaponSound() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Criticals.
         */
        if (modTags.Stats) {
            if (w.getCritDamage() != newWeap.getCritDamage() && newWeap.getCritDamage() != baseWeap.getCritDamage()) {
                w.setCritDamage(newWeap.getCritDamage());
                if (fullLogging) {
                    SPGlobal.log("Criticals: ", "Merged Crit Damage to " + w.getCritDamage() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        if (modTags.Stats) {
            if (w.getCritEffect() != newWeap.getCritEffect() && newWeap.getCritEffect() != baseWeap.getCritEffect()) {
                w.setCritEffect(newWeap.getCritEffect());
                if (fullLogging) {
                    SPGlobal.log("Criticals: ", "Merged Crit Effect to " + w.getCritEffect().getFormStr() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        if (modTags.Stats) {
            if (w.getCritMult() != newWeap.getCritMult() && newWeap.getCritMult() != baseWeap.getCritMult()) {
                w.setCritMult(newWeap.getCritMult());
                if (fullLogging) {
                    SPGlobal.log("Criticals: ", "Merged Crit Multiplier to " + w.getCritMult() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Description for weapons.
         */
        if (modTags.names) {
            if (!w.getDescription().equals(newWeap.getDescription()) && !newWeap.getDescription().equals(baseWeap.getDescription())) {
                w.setDescription(newWeap.getDescription());
                if (fullLogging) {
                    SPGlobal.log("Description: ", "Merged Description --" + w.getDescription() + "-- for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Draw sound (when unsheathing).
         */
        if (modTags.Sounds) {
            if (w.getDrawSound() != newWeap.getDrawSound() && newWeap.getDrawSound() != baseWeap.getDrawSound()) {
                w.setDrawSound(newWeap.getDrawSound());
                if (fullLogging) {
                    SPGlobal.log("Sounds: ", "Merged Draw Sound to " + w.getDrawSound().getFormStr() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Enchantment on weapon.
         */
        if (w.getEnchantment() != newWeap.getEnchantment() && newWeap.getEnchantment() != baseWeap.getEnchantment()) {
            w.setEnchantment(newWeap.getEnchantment());
            if (fullLogging) {
                SPGlobal.log("Enchantment: ", "Merged Enchantment to " + w.getEnchantment().getFormStr() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        /*
         * Enchantment charge for weapon.
         */
        if (modTags.Stats) {
            try {
                if (w.getEnchantmentCharge() != newWeap.getEnchantmentCharge() && newWeap.getEnchantmentCharge() != baseWeap.getEnchantmentCharge()) {
                    w.setEnchantmentCharge(newWeap.getEnchantmentCharge());
                    if (fullLogging) {
                        SPGlobal.log("Enchantment: ", "Merged Enchantment Charge to " + w.getEnchantmentCharge() + " for "
                                + newWeap.getEDID() + " from Mod " + temp.getName());
                    }
                }
            } catch (NullPointerException e) {
                SPGlobal.log("Error: ", "Null pointer exception on get/set enchantment charge.  Skipped. "
                        + "Most commonly caused by a weapon not having an enchantment charge set (and can thus be ignored).");
            }
        }

        /*
         * Equipment slot weapon uses.
         */
        if (w.getEquipmentSlot() != newWeap.getEquipmentSlot() && newWeap.getEquipmentSlot() != baseWeap.getEquipmentSlot()) {
            w.setEquipmentSlot(newWeap.getEquipmentSlot());
            if (fullLogging) {
                SPGlobal.log("Equip Slot: ", "Merged Equip Slot to " + w.getEquipmentSlot() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        /*
         * Impact set weapon uses (graphics when weapon impacts something, for
         * example).
         */
        if (modTags.Graphics) {
            if (w.getImpactSet() != newWeap.getImpactSet() && newWeap.getImpactSet() != baseWeap.getImpactSet()) {
                w.setImpactSet(newWeap.getImpactSet());
                if (fullLogging) {
                    SPGlobal.log("Impact: ", "Merged Impact Set to " + w.getImpactSet() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Range data on weapon.
         */
        if (modTags.Stats) {
            if (w.getMaxRange() != newWeap.getMaxRange() && newWeap.getMaxRange() != baseWeap.getMaxRange()) {
                w.setMaxRange(newWeap.getMaxRange());
                if (fullLogging) {
                    SPGlobal.log("Range: ", "Merged Max Range to " + w.getMaxRange() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        if (modTags.Stats) {
            if (w.getMinRange() != newWeap.getMinRange() && newWeap.getMinRange() != baseWeap.getMinRange()) {
                w.setMinRange(newWeap.getMinRange());
                if (fullLogging) {
                    SPGlobal.log("Range: ", "Merged Minimum Range to " + w.getMinRange() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Model the weapon uses.
         */
        if (modTags.Graphics) {
            if (w.getModelFilename() != null && newWeap.getModelFilename() != null) {
                if (!w.getModelFilename().equals(newWeap.getModelFilename()) && !newWeap.getModelFilename().equals(baseWeap.getModelFilename())) {
                    w.setModelFilename(newWeap.getModelFilename());
                    if (fullLogging) {
                        SPGlobal.log("Graphics: ", "Merged Model File to --" + w.getModelFilename() + "-- for "
                                + newWeap.getEDID() + " from Mod " + temp.getName());
                    }
                }
            }
        }

        /*
         * Name of the weapon.
         */
        if (modTags.names) {
            if (!w.getName().equals(newWeap.getName()) && !newWeap.getName().equals(baseWeap.getName())) {
                w.setName(newWeap.getName());
                if (fullLogging) {
                    SPGlobal.log("Names: ", "Merged Name to " + w.getName() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Number of projectiles for the weapon.
         */
        if (modTags.Stats) {
            if (w.getNumProjectiles() != newWeap.getNumProjectiles() && newWeap.getNumProjectiles() != baseWeap.getNumProjectiles()) {
                w.setNumProjectiles(newWeap.getNumProjectiles());
                if (fullLogging) {
                    SPGlobal.log("Projectiles: ", "Merged Number of Projectiles to " + w.getNumProjectiles() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Reach the weapon has.
         */
        if (modTags.Stats) {
            if (w.getReach() != newWeap.getReach() && newWeap.getReach() != baseWeap.getReach()) {
                w.setReach(newWeap.getReach());
                if (fullLogging) {
                    SPGlobal.log("Range: ", "Merged Reach to " + w.getReach() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Sheath sound the weapon has when putting weapon away.
         */
        if (modTags.Sounds) {
            if (w.getSheathSound() != newWeap.getSheathSound() && newWeap.getSheathSound() != baseWeap.getSheathSound()) {
                w.setSheathSound(newWeap.getSheathSound());
                if (fullLogging) {
                    SPGlobal.log("Sounds: ", "Merged Sheath Sound to " + w.getSheathSound().getFormStr() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * FOV for the weapon on sight. Believe it's a holdover from Fallout,
         * else used for bows?
         */
        if (modTags.Graphics) {
            if (w.getSightFOV() != newWeap.getSightFOV() && newWeap.getSightFOV() != baseWeap.getSightFOV()) {
                w.setSightFOV(newWeap.getSightFOV());
                if (fullLogging) {
                    SPGlobal.log("SightFOV: ", "Merged Sight FOV to " + w.getSightFOV() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Speed of the weapon.
         */
        if (modTags.Stats) {
            if (w.getSpeed() != newWeap.getSpeed() && newWeap.getSpeed() != baseWeap.getSpeed()) {
                w.setSpeed(newWeap.getSpeed());
                if (fullLogging) {
                    SPGlobal.log("Speed: ", "Merged Speed to " + w.getSpeed() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * The stagger impact of the weapon.
         */
        if (modTags.Stats) {
            if (w.getStagger() != newWeap.getStagger() && newWeap.getStagger() != baseWeap.getStagger()) {
                w.setStagger(newWeap.getStagger());
                if (fullLogging) {
                    SPGlobal.log("Stagger: ", "Merged Stagger to " + w.getStagger() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * The sound the weapon makes when swinging.
         */
        if (modTags.Sounds) {
            if (w.getSwingSound() != newWeap.getSwingSound() && newWeap.getSwingSound() != baseWeap.getSwingSound()) {
                w.setSwingSound(newWeap.getSwingSound());
                if (fullLogging) {
                    SPGlobal.log("Sounds: ", "Merged Swing Sound to " + w.getSwingSound().getFormStr() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * The template the weapon takes from (for enchanted variants).
         */
        if (w.getTemplate() != newWeap.getTemplate() && newWeap.getTemplate() != baseWeap.getTemplate()) {
            w.setTemplate(newWeap.getTemplate());
            if (fullLogging) {
                SPGlobal.log("Template: ", "Merged Template to " + w.getTemplate().getFormStr() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        /*
         * VATS data? Probably holdover field.
         */
        if (w.getVATS() != newWeap.getVATS() && newWeap.getVATS() != baseWeap.getVATS()) {
            w.setVATS(newWeap.getVATS());
            if (fullLogging) {
                SPGlobal.log("VATS: ", "Merged VATS to " + w.getVATS() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        /*
         * Value of the weapon.
         */
        if (modTags.Stats) {
            if (w.getValue() != newWeap.getValue() && newWeap.getValue() != baseWeap.getValue()) {
                w.setValue(newWeap.getValue());
                if (fullLogging) {
                    SPGlobal.log("Value: ", "Merged Value to " + w.getValue() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        /*
         * Weapon type.
         */
        if (w.getWeaponType() != newWeap.getWeaponType() && newWeap.getWeaponType() != baseWeap.getWeaponType()) {
            w.setWeaponType(newWeap.getWeaponType());
            if (fullLogging) {
                SPGlobal.log("WeaponType: ", "Merged Weapon Type to " + w.getWeaponType() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        /*
         * Weight of the weapon.
         */
        if (modTags.Stats) {
            if (w.getWeight() != newWeap.getWeight() && newWeap.getWeight() != baseWeap.getWeight()) {
                w.setWeight(newWeap.getWeight());
                if (fullLogging) {
                    SPGlobal.log("Weight: ", "Merged Weight to " + w.getWeight() + " for "
                            + newWeap.getEDID() + " from Mod " + temp.getName());
                }
            }
        }

        //Unknown data, last mod wins.
        if (w.getDNAMUnknown1() != newWeap.getDNAMUnknown1() && newWeap.getDNAMUnknown1() != baseWeap.getDNAMUnknown1()) {
            w.setDNAMUnknown1(newWeap.getDNAMUnknown1());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getDNAMUnknown2() != newWeap.getDNAMUnknown2() && newWeap.getDNAMUnknown2() != baseWeap.getDNAMUnknown2()) {
            w.setDNAMUnknown2(newWeap.getDNAMUnknown2());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getDNAMUnknown3() != newWeap.getDNAMUnknown3() && newWeap.getDNAMUnknown3() != baseWeap.getDNAMUnknown3()) {
            w.setDNAMUnknown3(newWeap.getDNAMUnknown3());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getDNAMUnknown5() != newWeap.getDNAMUnknown5() && newWeap.getDNAMUnknown5() != baseWeap.getDNAMUnknown5()) {
            w.setDNAMUnknown5(newWeap.getDNAMUnknown5());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getDNAMUnknown6() != newWeap.getDNAMUnknown6() && newWeap.getDNAMUnknown6() != baseWeap.getDNAMUnknown6()) {
            w.setDNAMUnknown6(newWeap.getDNAMUnknown6());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getDNAMUnknown7() != newWeap.getDNAMUnknown7() && newWeap.getDNAMUnknown7() != baseWeap.getDNAMUnknown7()) {
            w.setDNAMUnknown7(newWeap.getDNAMUnknown7());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getDNAMUnknown8() != newWeap.getDNAMUnknown8() && newWeap.getDNAMUnknown8() != baseWeap.getDNAMUnknown8()) {
            w.setDNAMUnknown8(newWeap.getDNAMUnknown8());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getCRDTUnknown() != newWeap.getCRDTUnknown() && newWeap.getCRDTUnknown() != baseWeap.getCRDTUnknown()) {
            w.setCRDTUnknown(newWeap.getCRDTUnknown());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getCRDTUnknown0() != newWeap.getCRDTUnknown0() && newWeap.getCRDTUnknown0() != baseWeap.getCRDTUnknown0()) {
            w.setCRDTUnknown0(newWeap.getCRDTUnknown0());
            if (fullLogging) {
                SPGlobal.log("Unknown: ", "Merged Extraneous/Unknown Data for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getBAMT() != newWeap.getBAMT() && newWeap.getBAMT() != baseWeap.getBAMT()) {
            w.setBAMT(newWeap.getBAMT());
            if (fullLogging) {
                SPGlobal.log("VATS: ", "Merged VATS to " + w.getBAMT() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getBIDS() != newWeap.getBIDS() && newWeap.getBIDS() != baseWeap.getBIDS()) {
            w.setBIDS(newWeap.getBIDS());
            if (fullLogging) {
                SPGlobal.log("VATS: ", "Merged VATS to " + w.getBIDS() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getSNAM() != newWeap.getSNAM() && newWeap.getSNAM() != baseWeap.getSNAM()) {
            w.setSNAM(newWeap.getSNAM());
            if (fullLogging) {
                SPGlobal.log("VATS: ", "Merged VATS to " + w.getSNAM() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getVNAM() != newWeap.getVNAM() && newWeap.getVNAM() != baseWeap.getVNAM()) {
            w.setVNAM(newWeap.getVNAM());
            if (fullLogging) {
                SPGlobal.log("VATS: ", "Merged VATS to " + w.getVNAM() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        if (w.getWNAM() != newWeap.getWNAM() && newWeap.getWNAM() != baseWeap.getWNAM()) {
            w.setWNAM(newWeap.getWNAM());
            if (fullLogging) {
                SPGlobal.log("VATS: ", "Merged VATS to " + w.getBAMT() + " for "
                        + newWeap.getEDID() + " from Mod " + temp.getName());
            }
        }

        return w;
    }
}
